﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net.Mail;
using GadgetStore.Web.Adapters.Interfaces;
using GadgetStore.Data.Models;
using GadgetStore.Data;

namespace GadgetStore.Web.Adapters
{
    public class EmailAdapter : IEmail
    {
        //Does this need to be static
        public string SendEmail(Email email)
        {
            MailMessage mailMessage = new MailMessage("spygirls67@gmail.com", "spygirls67@gmail.com");
            mailMessage.Subject = "Message from FemmeFatale Website";
            mailMessage.Body = "Sender's Email: " + email.SenderAddress;
            mailMessage.Body += "          Sender's Messge: " + email.EmailBody;
            SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587);
            smtpClient.Credentials = new System.Net.NetworkCredential()
            {
                UserName = "spygirls67@gmail.com",
                Password = "wearethebest!"
            };
            smtpClient.EnableSsl = true;
            smtpClient.Send(mailMessage);
            ApplicationDbContext Db = new ApplicationDbContext();
            Email NewEmail = new Email();
            NewEmail.EmailBody = email.EmailBody;
            NewEmail.SenderAddress = email.SenderAddress;
            Db.Emails.Add(NewEmail);
            Db.SaveChanges();
            return ("Your message was sent!");
        }
    }
}